package com.roger.myHome.service.impl;


import com.roger.myHome.domain.TbMedicalHistory;
import com.roger.myHome.entity.qto.MedicalHistoryQry;
import com.roger.myHome.entity.vo.MedicalHistoryVo;
import com.roger.myHome.mapper.MedicalHistoryMapper;
import com.roger.myHome.page.EUDataGridResult;
import com.roger.myHome.service.MedicalHistoryService;
import com.roger.myHome.util.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Slf4j
public class MedicalHistoryServiceImpl implements MedicalHistoryService {

    @Resource
    private MedicalHistoryMapper medicalHistoryMapper;

    @Override
    public EUDataGridResult page(MedicalHistoryQry qry) {
        List<MedicalHistoryVo> list = medicalHistoryMapper.page(qry);
        return new EUDataGridResult(list,medicalHistoryMapper.totalSize(qry));
    }

    @Override
    public String add(TbMedicalHistory entity) {
        medicalHistoryMapper.insert(entity);
        Map<String, String> hp = new HashMap<>();
        hp.put("result", "success");
        return StringUtils.getJSONString(hp);
    }

    @Override
    public String delete(Long id) {
        medicalHistoryMapper.deleteById(id);
        Map<String, String> hp = new HashMap<>();
        hp.put("result", "success");
        return StringUtils.getJSONString(hp);
    }

    @Override
    public MedicalHistoryVo getVo(Long userId,Long id) {
        MedicalHistoryQry qry = new MedicalHistoryQry();
        qry.setId(id);
        qry.setPage(0);
        qry.setUserId(userId);
        qry.setRows(10);
        List<MedicalHistoryVo> list = medicalHistoryMapper.page(qry);
        return list.get(0);
    }
}
